CORONADO ENTERPRISES ADA TUTORIAL - PART 1 - BEGINNING ADA This documentation and the accompanying software, including all of the example Ada programs and text files, are protected under United States copyright law to protect them from unauthorized commercialization. This version of the tutorial is distributed under the shareware concept, which means you are not required to pay for it. You are permitted to copy the disks, and pass copies on to a friend, provided you do not modify any files or omit any files from the complete package. In fact, you are encouraged to pass complete copies on to friends. You are permitted to charge a small fee to cover the costs of duplication, but you are not permitted to charge anything for the software itself. If you find the tutorial helpful, you are encouraged to register with the author and to submit a small fee to help compensate him for his time and expense in writing it. We will provide you with a beautifully printed copy of this tutorial if you submit a full registration. See the READ.ME1 file on either diskette for addi- tional details. Whether or not you send a registration fee, feel free to request a copy of the latest list of available tutorials and a list of the authorized Public Domain libraries that distribute our full line of programming language tutorials. Gordon Dodrill - July 1, 1991 Copyright (c) 1988, 1991, Coronado Enterprises Coronado Enterprises 12501 Coronado Ave NE Albuquerque, New Mexico 87122 Ada is a registered trademark of the U. S. Government (Ada Joint Program Office). TABLE OF CONTENTS Part 1 - Beginning Ada Introduction to the Ada tutorial. Page I-1 Chapter 1 - Getting started. Page 1-1 Chapter 2 - Program structure. Page 2-1 TRIVIAL.ADA The minimum Ada program 2-1 SOMEOUT.ADA A little output 2-2 MOREOUT.ADA More output 2-3 GOODFORM.ADA Good formatting example 2-4 UGLYFORM.ADA Very bad formatting 2-5 COMMENTS.ADA Ada comments 2-5 Chapter 3 - The integer type variable. Page 3-1 ONEINT.ADA The INTEGER variable 3-1 MOREINTS.ADA More INTEGER variables 3-4 INITEX.ADA Integer initialization 3-6 SUBTYPES.ADA Ada subtypes 3-7 INTATTRS.ADA Integer attributes 3-11 Chapter 4 - Logical compares & precedence. Page 4-1 COMPARE.ADA The BOOLEAN variable 4-1 COMPARES.ADA Boolean expressions 4-2 Chapter 5 - Control Structures. Page 5-1 LOOPDEMO.ADA Simple loops 5-1 MORELOOP.ADA More uses of loops 5-3 IFDEMO.ADA Conditional statements 5-6 CASEDEMO.ADA Another conditional 5-7 GOTODEMO.ADA The GOTO statement 5-8 TEMPCONV.ADA A useful program 5-9 DUMBCONV.ADA A poorly written program 5-9 Chapter 6 - Additional scalar types. Page 6-1 ALLINT.ADA Integer type variables 6-1 ENUM.ADA The enumerated variable 6-3 BOOLVARS.ADA The BOOLEAN variable 6-6 INCRINT.ADA Integer operations 6-7 FLOATVAR.ADA The floating point variable 6-7 FIXED.ADA The fixed point variable 6-10 MIXTYPES.ADA Simple type conversions 6-11 Chapter 7 - Derived types. Page 7-1 DERTYPES.ADA Derived types 7-2 DERSUBS.ADA Derived subtypes 7-5 MOREDERS.ADA More derived types 7-6 Chapter 8 - Subprograms. Page 8-1 PROCED1.ADA A simple procedure 8-1 PROCED2.ADA Several procedures 8-2 PROCED3.ADA A procedure with parameters 8-3 CALLING.ADA Procedures calling procedures 8-5 NESTING.ADA Procedure nesting 8-5 Chapter 8 - Subprograms (continued) Page 8-1 FUNCT.ADA A simple function 8-6 ODDSQRE.ADA Procedure nesting example 8-7 OVERLOAD.ADA Overloading illustration 8-8 Chapter 9 - Blocks and scope of variables. Page 9-1 SCOPE.ADA Scope of variables 9-1 SCOPE2.ADA Scope of variables 9-2 BLOCKS.ADA The ADA block 9-3 AUTOMATC.ADA What are automatic variables? 9-4 Chapter 10 - Arrays. Page 10-1 ARRAY1.ADA Simple arrays 10-1 SLICE.ADA The Ada slice 10-4 MULTARY1.ADA A multidimensional array 10-5 MULTARY2.ADA A multidimensional array 10-6 MULTARY3.ADA A multidimensional array 10-6 ARRYINIT.ADA Initializing arrays 10-7 Chapter 11 - The character & string types. Page 11-1 CHARS.ADA The CHARACTER variable 11-1 STRING1.ADA The STRING variable 11-1 CONCAT.ADA String concatenation 11-3 STRNGCMP.ADA String comparisons 11-3 CHARINT.ADA CHAR & INT conversions 11-4 Chapter 12 - Records. Page 12-1 RECORD1.ADA A simple record 12-1 RECORD2.ADA A nested record 12-3 RECORD3.ADA An array in a record 12-4 RECORD4.ADA An array of records 12-5 Chapter 13 - The access type variable. Page 13-1 ACCESS1.ADA The access variable & INTEGER 13-1 ACCESS2.ADA The access variable & FLOAT 13-3 ACCESS3.ADA The access variable & records 13-3 ACCESS4.ADA The access variable & arrays 13-6 ACCESS5.ADA An array of access variables 13-6 Chapter 14 - Input/Output. Page 14-1 FORMATS.ADA Output formatting 14-1 EASYOUT.ADA File output 14-2 MULTOUT.ADA Multiple file output 14-3 CHARIN.ADA CHARACTER input 14-4 STRINGIN.ADA STRING input 14-6 INTIN.ADA INTEGER input 14-6 PRINTOUT.ADA Using the printer 14-7 Chapter 15 - Packages. Page 15-1 ADDERPKG.ADA A separately compiled package 15-1 ADDER1.ADA Using the package ADDERPKG 15-4 ADDER2.ADA A package in a definition part 15-6 ADDER3.ADA Separate body compilation 15-7 ADDERSTB.ADA A body stub 15-7 ADDER4.ADA Initialization section 15-8 Chapter 16 - Example Programs. Page 16-1 CHARSTAK.ADA A simple stack implementation 16-1 TRYSTAK.ADA Using the simple stack 16-2 DYNSTRNG.ADA A dynamic string package 16-2 TRYSTRNG.ADA Using the dynamic string 16-4 AGE.ADA How many days old are you? 16-5 Part 2 - Advanced Ada Chapter 17 - Exceptions. Page 17-1 EXCEPT1.ADA A simple exception 17-1 EXCEPT2.ADA My own simple exception 17-3 EXCEPT3.ADA Exception propagation 17-5 EXCEPT4.ADA Recovery from an exception 17-6 EXCEPT5.ADA Additional exception topics 17-7 Chapter 18 - Advanced Subprogram topics. Page 18-1 DEFAULTS.ADA Simple defaults 18-1 DEFAULT2.ADA Variable defaults 18-2 RECURSON.ADA Simple recursion 18-3 FUNCRECR.ADA Function recursion 18-4 REVERS.ADA Function returning an array 18-6 Chapter 19 - Advanced Array topics. Page 19-1 SUMMER.ADA An unconstrained array 19-1 ENUMARY.ADA An enumerated array index 19-2 ARRAYOPS.ADA Array operators 19-3 ARRAYOP2.ADA Operator overloading 19-4 UNARYOP.ADA Unary operator overloading 19-5 Chapter 20 - Advanced record topics. Page 20-1 DISCRIM1.ADA A simple discriminant 20-1 DISCRIM2.ADA Flexible functions 20-2 DISCRIM3.ADA A variable discriminant 20-3 DISCRIM4.ADA A multiple discriminant 20-4 VARIANT1.ADA A variant record 20-4 VARIANT2.ADA A variable variant record 20-6 INFIX.ADA Operator overloading 20-7 Chapter 21 - Advanced packages & private types Page 21-1 NOPRIVAT.ADA No private type 21-1 PRIVAT1.ADA A private type 21-2 PRIVAT2.ADA A modified private type 21-4 LIMPRIV.ADA A limited private type 21-4 Chapter 22 - Binary Input/Output Page 22-1 BISEQOUT.ADA Binary sequential output 22-1 BISEQIN.ADA Binary sequential input 22-3 BIRANDIO.ADA Binary random input/output 22-4 Chapter 23 - Dynamic Allocation. Page 23-1 LINKLIST.ADA A linked list 23-1 SORTLIST.ADA A sorting linked list 23-4 BTREE.ADA A sorting binary tree 23-6 Chapter 24 - Tasking. Page 24-1 TIMER.ADA Simple Tasking Example 24-1 TASK1.ADA Simple Tasking 24-4 TASK2.ADA Simple Tasking with Delays 24-7 TASK3.ADA Tasking in a Code Block 24-7 Chapter 25 - The Simple Rendezvous. Page 25-1 HOTDOG.ADA The Simple Rendezvous 25-1 HOTDOGS.ADA Parameter Passing 25-4 MANYDOGS.ADA Multiple Callers 25-5 RETAIL1.ADA The Select Statement 25-7 RETAIL2.ADA The Guarding Condition 25-8 Chapter 26 - The Conditional Rendezvous. Page 26-1 MEALS1.ADA The Select Statement 26-1 MEALS2.ADA The Conditional Select 26-2 MEALS3.ADA The Delayed Select 26-4 TERMINAT.ADA Proper Termination 26-5 Chapter 27 - Additional Tasking Topics. Page 27-1 TASKTYPE.ADA The Tasking Type 27-1 TASKARRY.ADA An Array of Tasks 27-3 TASKACES.ADA A Task Access Variable 27-3 PARALLEL.ADA Parallel Computation 27-4 PRIORITY.ADA Tasking Priority 27-5 FAMILY.ADA A Family of Task Entries 27-6 Chapter 28 - Generic Subprograms. Page 28-1 SWAPSOME.ADA A Generic Procedure 28-1 SWAPMORE.ADA Generic Subprograms 28-4 ALLGENER.ADA Generic Formal Parameters 28-6 ARRAYGEN.ADA Array Type Generics 28-7 ACCESGEN.ADA Access Type Generics 28-9 Chapter 29 - Generic Packages. Page 29-1 GENPKG.ADA Simple Generic Parameters 29-1 NESTPKG.ADA Embedded Generic Packages 29-2 OBJGEN.ADA Generic Object Parameters 29-3 PROCPKG.ADA Generic Procedure Parameters 29-4 FUNCPKG.ADA Generic Function Parameters 29-5 Chapter 30 - Control of Representation. Page 30-1 SMALLINT.ADA The Length Specification 30-2 BITFIELD.ADA The Record Type Representation 30-4 PACKITIN.ADA The PACK Pragma 30-6 ENUMREP.ADA Enumerated Type Representation 30-7 Chapter 31 - More Example Programs. Page 31-1 RANDOM.ADA Random Number Generator 31-1 TESTRAN.ADA Test Random Numbers 31-1 DYNSTRNG.ADA Dynamic String Package 31-2 TESTSTRN.ADA Test Dynamic Strings 31-2 TRYSTRNG.ADA Using the dynamic string 31-3 AGE2.ADA How old are you? 31-3 PHILOS.ADA Tasking Example 31-3 GENSTACK.ADA Generic Stack 31-5 TRYSTAK.ADA Try Generic Stack 31-5 Note: Even though this is only Part 1 (Beginning Ada) of the Ada tutorial, the entire table of contents is listed for the students convenience. ABOUT THE AUTHOR _________________________________________________________________ The author of this tutorial began programming in 1961 using FORTRAN on an IBM 1620. Since then, most of his career has been involved with designing digital logic for satellite applications. In 1983, being somewhat burned out with logic design, he began a study of some of the more modern programming languages and has since made a complete career shift to software development. After learning Pascal, C was studied, followed by Modula-2 and Ada, and more recently C++. Rather than simply learning the syntax of each new language, modern methods of software engineering were studied and applied to effectively utilize the languages. He is currently employed by a large research and development laboratory where he continues to study, teach, and apply the newer programming languages.